/*
 * Project: Daycare Web Application
 * Package: com.made2ordersoftware.daycare.domain
 * File:    AuthenticationEntity.java
 * Created: Dec 20, 2010
 */

/*
 *  Copyright (c) 2010 Made 2 Order Software, LLC
 *
 *  All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 *  transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 *  You may not distribute the URL or redistribute the files to third parties. You may transfer the files
 *  onto a single storage device so long as you can prove ownership of the software. You may not reverse
 *  engineer, decompile, or disassemble the software or media files. You may not modify or translate the
 *  software or media, or distribute copies of the software or media without the written consent of Made
 *  2 Order Software
 */
package com.made2ordersoftware.daycare.domain;

import com.made2ordersoftware.util.StringUtility;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Entity class representing any user of the day care which has authentication privileges to the system.
 *
 * @author David Canning <dcannin@gmail.com>
 * @version 1.0.0
 */
@Entity
@Table(name = "authentication")
@NamedQueries({
    @NamedQuery(name = "Authentication.authenticationUser", query = "SELECT a from AuthenticationEntity a WHERE a.userName = :userName and a.password = :password"),})
@XmlRootElement
public class AuthenticationEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final Logger LOG = LoggerFactory.getLogger(AuthenticationEntity.class);
    @Id
    private Long id;
    @Basic(optional = false)
    @Column(name = "user_name")
    private String userName;
    @Basic(optional = false)
    private String password;
    @MapsId
    @JoinColumn(name = "id", referencedColumnName = "id")
    @OneToOne(optional = false)
    private PersonEntity person;

    /**
     * Creates an instance of <code>AuthenticationEntity</code>.
     */
    public AuthenticationEntity() {
    }

    /**
     * Creates an instance of <code>AuthenticationEntity</code>.
     *
     * @param userName User name of person logging into the system
     * @param password Password of user logging into the system
     */
    public AuthenticationEntity(String userName, String password) {
        this.userName = userName;
        this.password = password;
    }

    /**
     *
     * @return
     */
    public Long getId() {
        return id;
    }

    /**
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     *
     * @return
     */
    public String getUserName() {
        return userName;
    }

    /**
     *
     * @param userName
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     *
     * @return
     */
    public String getPassword() {
        return password;
    }

    /**
     *
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     *
     * @return
     */
    public PersonEntity getPerson() {
        return person;
    }

    /**
     *
     * @param person
     */
    public void setPerson(PersonEntity person) {
        this.person = person;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 19 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof AuthenticationEntity)) {
            return false;
        }
        AuthenticationEntity other = (AuthenticationEntity) object;
        return Objects.equals(this.id, other.getId());
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("\nAuthenticationEntity{ id=").append(
                StringUtility.ifNotNullToString(getId()));
        sb.append(",\\tnuserName=").append(getUserName());
        sb.append(",\n\tpassword=").append(getPassword());
        sb.append("}");
        return sb.toString();

    }

}
